<template>
  <div class="foryou">
    <div class="wrap">
      <div class="title">
        <h2>为你推荐</h2>
      </div>
      <div class="table-wrapper">
        <ul class="feed-tab">
          <li class="feed-tab__item">
            <div class="item-title">
              <span class="item-title-text">精选</span>
            </div>
            <div class="item-desc">猜你喜欢</div>
            <div class="item-gap"></div>
          </li>
          <li class="feed-tab__item">
            <div class="item-title">
              <span class="item-title-text">智能先锋</span>
            </div>
            <div class="item-desc">大电器城</div>
            <div class="item-gap"></div>
          </li>
          <li class="feed-tab__item">
            <div class="item-title">
              <span class="item-title-text">居家优品</span>
            </div>
            <div class="item-desc">品质生活</div>
            <div class="item-gap"></div>
          </li>
          <li class="feed-tab__item">
            <div class="item-title">
              <span class="item-title-text">超市百货</span>
            </div>
            <div class="item-desc">百货生鲜</div>
            <div class="item-gap"></div>
          </li>
          <li class="feed-tab__item">
            <div class="item-title">
              <span class="item-title-text">时尚达人</span>
            </div>
            <div class="item-desc">美妆穿搭</div>
            <div class="item-gap"></div>
          </li>
          <li class="feed-tab__item">
            <div class="item-title">
              <span class="item-title-text">进口好货</span>
            </div>
            <div class="item-desc">国际商城</div>
          </li>
        </ul>
      </div>
      <div class="shop">
        <ul class="clearfix">
          <li
            v-for="(item, index) in arr"
            :key="index"
            @click="tocommodity(item, index)"
          >
            <div class="lazy">
              <img :src="item.goodsImage" alt="" srcset="" />
            </div>
            <div class="info">
              <p class="info-name">
                <i class="info-self">自营</i>
                {{ item.goodsName }}
              </p>
              <div class="info-price">
                <i>￥</i>
                <span class="price-txt">{{ item.goodsPrice }}</span>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      arr: [],
    };
  },
  methods: {
    tocommodity(item, index) {
      this.$router.push({
        path: "/commodityDetails",
        query: { goodsid: this.arr[index].goodsId, id: this.arr[index].skuId },
      });
    },
  },
  mounted() {
    this.$axios.post("/goods/getListByRecommend ").then((res) => {
      this.arr = res.data.data;
    });
  },
};
</script>
<style scoped>
.info {
  padding: 0 20px;
  font-size: 14px;
  line-height: 24px;
}
.info-name {
  height: 49px;
  color: #666;
  overflow: hidden;
}
.info-self {
  background-color: #e23a3a;
  border-radius: 2px;
  font-size: 13px;
  margin-right: 5px;
  padding: 2px 5px;
  color: white;
}
.info-price {
  color: rgb(225, 37, 27);
  margin-top: 10px;
  font-size: 22px;
}
.info-price i {
  font-size: 16px;
}
.price-txt {
  margin-left: -5px;
}
.title {
  padding-top: 30px;
  padding-bottom: 30px;
  text-align: center;
}
h2 {
  font-size: 28px;
  position: relative;
}
h2::before {
  content: "";
  position: absolute;
  top: 50%;
  margin-top: -10px;
  background-image: url("../../static/img/title.png");
  width: 25px;
  height: 20px;
  background-position: 0 0;
  left: 500px;
}
h2::after {
  content: "";
  position: absolute;
  top: 50%;
  margin-top: -10px;
  background-image: url("../../static/img/title.png");
  width: 25px;
  height: 20px;
  background-position: 0 0;
  right: 500px;
}
.table-wrapper {
  background: #fff;
  margin-bottom: 10px;
}
.feed-tab {
  margin: 0 auto;
  height: 60px;
  width: 1080px;
}
.feed-tab__item {
  position: relative;
  float: left;
  width: 180px;
  height: 60px;
  text-align: center;
  cursor: pointer;
}
li:hover {
  cursor: pointer;
}
.item-title {
  color: #333;
  margin-top: 7px;
  font-size: 16px;
  font-weight: 700;
  line-height: 27px;
  height: 27px;
}
.item-title-text {
  background: #e1251b;
  color: #fff;
  width: 70px;
  height: 27px;
  display: inline-block;
  border-radius: 50px;
  padding: 0 5px;
}
.item-desc {
  color: #e1251b;
}
.item-gap {
  position: absolute;
  right: 0;
  top: 0;
  height: 40px;
  margin: 10px 0;
  width: 1px;
  background: linear-gradient(180deg, white, #dfdfdf 51%, white);
}
.shop ul {
  margin: 0 -5px;
}
.lazy {
  width: 150px;
  height: 150px;
  margin: 30px auto 40px;
}
.shop li {
  position: relative;
  float: left;
  width: 230px;
  height: 322px;
  margin: 0 5px 10px;
  background: #fff;
}
.lazy img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
}
</style>